create or replace view vac_button_templates_4_1 as
with v_templ_button as
(
select
 workspace,
 workspace_display_name,
 application_id,
 application_name,
 theme_number,
 theme_class,
 template_name,
 ac_utils.hs(template) template_hs,
 dbms_lob.substr(template, 4000, 1)        template_sr1,
 dbms_lob.substr(template, 4000, 4000+1 )  template_sr2,
 dbms_lob.substr(template, 4000, 8000+1 )  template_sr3,
 dbms_lob.substr(template, 4000, 12000+1)  template_sr4,
 ac_utils.hs(hot_template) hot_template_hs,
 dbms_lob.substr(hot_template, 4000, 1)        hot_template_sr1,
 dbms_lob.substr(hot_template, 4000, 4000+1 )  hot_template_sr2,
 dbms_lob.substr(hot_template, 4000, 8000+1 )  hot_template_sr3,
 dbms_lob.substr(hot_template, 4000, 12000+1)  hot_template_sr4,
 is_subscribed,
 subscribed_from,
 last_updated_by,
 last_updated_on,
 translatable,
 component_comment,
 button_template_id,
 component_signature
from apex_application_temp_button
)
select
   workspace,
   workspace_display_name,
   application_id,
   application_name,
   theme_number,
   theme_class,
   template_name,
   to_clob(template_sr1) || to_clob(template_sr2)
   || to_clob(template_sr3) || to_clob(template_sr4) template_sr,
   to_clob(hot_template_sr1) || to_clob(hot_template_sr2)
   || to_clob(hot_template_sr3) || to_clob(hot_template_sr4) hot_template_sr,
   last_updated_by,
   last_updated_on,
   component_comment,
   button_template_id,
   component_signature,
   'APEX_APPLICATION_TEMP_BUTTON' src_view_name,
   u_value,
   u_name
from
(
  select
   workspace,
   workspace_display_name,
   application_id,
   application_name,
   theme_number,
   theme_class,
   template_name,
   template_sr1,     template_sr2,     template_sr3,     template_sr4,
   hot_template_sr1, hot_template_sr2, hot_template_sr3, hot_template_sr4,
   last_updated_by,
   last_updated_on,
   component_comment,
   button_template_id,
   component_signature,
   u_value,
   u_name
  from v_templ_button
  UNPIVOT INCLUDE NULLS
   ( u_value
     FOR    u_name
     IN
     (
      template_hs,
      hot_template_hs,
      is_subscribed,
      subscribed_from,
      translatable
     )
   )
) t;

